package javabase.thinkinjava.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author fance
 * @date 18-4-30 上午9:27
 */
public class LargeMappedFiles {
    // 128M
    static int len = 0x8FFFFFF;

    public static void main(String[] args) throws IOException {
        MappedByteBuffer out = new RandomAccessFile("test.dat","rw").getChannel()
                .map(FileChannel.MapMode.READ_WRITE,0,len);
        for (int i = 0; i < len; i++) {
            out.put((byte) 'x');
        }
        System.out.println("finish ...");
        for (int i = len / 2; i < len / 2 + 6; i++) {
            System.out.print((char)out.get(i) + " ");
        }
    }
}
